var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("GlobalParam"),
    l = e("Util"),
    d = e("GameData"),
    u = e("ProgressTaskData"),
    p = e("SkinLevelData"),
    h = cc._decorator,
    f = h.ccclass,
    _ = h.property,
    y = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.item_finish = null),
                (t.item_bg = null),
                (t.progressTask = null),
                (t.items = []),
                (t.taskIndex = 0),
                (t.btnClose = null),
                (t.btn_receive = null),
                (t.receiveList = []),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onResetView = function () {
                if ((cc.SDK.showBanner(), d.default.instance.gameState == d.GameState.play)) {
                    var e = d.default.instance.SelfPlayerData;
                    e && e.fraction && u.default.instance.setScore(e.fraction);
                }
                (this.isCache = !1),
                    ad.curr_platform == window.ad.Platform.WECHAT && ad.adInterface.showBanner(),
                    ad.curr_platform == window.ad.Platform.QQ && ad.adInterface.showBanner(),
                    ad.curr_platform == window.ad.Platform.TOU_TIAO && ad.adInterface.showBanner(),
                    ad.curr_platform == window.ad.Platform.MEI_ZU && ad.adInterface.showInterstitial(),
                    ad.curr_platform == window.ad.Platform.HUAWEI_GAME && ad.adInterface.showNativeInterstitial(),
                    ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.showBanner();
            }),
            (t.prototype.onDisable = function () {
                cc.SDK.hideBanner(), ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.hideBanner(!1);
            }),
            (t.prototype.onInitView = function () {
                d.default.instance.gameState = d.GameState.finish;
                var e = u.default.instance.getScore(),
                    t = u.default.instance.taskListScore,
                    o = u.default.instance.getTaskProgressIndex();
                0 == o
                    ? (this.progressTask.progress = (e / t[o]) * 0.2)
                    : o >= t.length
                    ? (this.progressTask.progress = 1)
                    : (this.progressTask.progress = 0.2 * o + (e / t[o]) * 0.2),
                    (this.taskIndex = o),
                    this.refreshView();
            }),
            (t.prototype.refreshView = function () {
                var e = u.default.instance.taskListScore;
                this.receiveList = [];
                for (var t = 0; t < e.length; t++) {
                    if (t < this.taskIndex)
                        this.items[t].getChildByName("item_bg").getComponent(cc.Sprite).spriteFrame = this.item_finish;
                    else {
                        this.items[t].getChildByName("item_bg").getComponent(cc.Sprite).spriteFrame = this.item_bg;
                        var o = cc.Material.getBuiltinMaterial("2d-gray-sprite");
                        this.items[t]
                            .getChildByName("item_bg")
                            .getChildByName("item_1")
                            .getComponent(cc.Sprite)
                            .setMaterial(0, o);
                    }
                    "true" == l.default.getItem("ProgressTaskItem" + (t + 1), "0")
                        ? (this.items[t].getChildByName("item_bg").getChildByName("finish_mask").active = !0)
                        : (this.items[t].getChildByName("item_bg").getChildByName("finish_mask").active = !1),
                        "true" != l.default.getItem("ProgressTaskItem" + (t + 1), "0") &&
                            t < this.taskIndex &&
                            this.receiveList.push(t);
                }
                this.btn_receive.interactable = 0 != this.receiveList.length;
            }),
            (t.prototype.itemClick = function (e) {
                if (!e.target.getChildByName("finish_mask").active) {
                    var t = e.target.index;
                    t >= this.taskIndex || (this.getReward(t), this.refreshView());
                }
            }),
            (t.prototype.getReward = function (e) {
                l.default.setItem("ProgressTaskItem" + (e + 1), "true");
                var t = u.default.instance.rewardList[e];
                if ("fragment" == t.skinType) {
                    var o = d.default.instance.getPlayerCoin();
                    d.default.instance.setPlayerCoin(o + t.num);
                    var n = u.default.instance.taskListName[e];
                    game.UIManager.instance.showToast(n);
                } else {
                    for (
                        var i = l.default.randomFrom(0, t.skinType.length - 1),
                            a = t.skinType[i],
                            r = p.SkinLevelData.instance.skinList,
                            s = 0;
                        s < r.length;
                        s++
                    ) {
                        var c = r[s];
                        if (c.chinese == a) {
                            p.SkinLevelData.instance.add_fragments(c, t.num);
                            break;
                        }
                    }
                    game.UIManager.instance.showToast(a + "碎片*" + t.num);
                }
            }),
            (t.prototype.btn_closeView = function () {
                if ((this.closeView(!1), ad.curr_platform == window.ad.Platform.TOU_TIAO)) {
                    for (
                        var e = {type: "", data: null}, t = p.SkinLevelData.instance.skinList, o = null, n = 0;
                        n < t.length;
                        n++
                    )
                        (r = t[n]).isLock || (o = r);
                    if (o)
                        return (
                            (e.type = "skin"),
                            (e.data = o),
                            void game.PopupManager.instance.showPopView(s.default.PopupMap.GetSkinlView, e, !1, !1)
                        );
                    var i = null,
                        a = c.default.DecorateData;
                    for (n = 0; n < a.length; n++) {
                        var r = a[n];
                        if ("true" != l.default.getItem("dressItemLock" + r.index, "false")) {
                            i = r;
                            break;
                        }
                    }
                    if (i)
                        return (
                            (e.type = "decorate"),
                            (e.data = i),
                            void game.PopupManager.instance.showPopView(s.default.PopupMap.GetSkinlView, e, !1, !1)
                        );
                }
                ad.curr_platform == window.ad.Platform.OPPO && ad.adInterface.isNativePatchReady()
                    ? game.PopupManager.instance.showPopView(s.default.PopupMap.SettlementView2, null, !1, !1)
                    : game.PopupManager.instance.showPopView(s.default.PopupMap.SettlementView, null, !1, !1);
            }),
            (t.prototype.onClick_btn_receive = function () {
                var e = this.receiveList[0];
                this.getReward(e), this.refreshView();
            }),
            (t.prototype.addEvent = function () {
                for (var e = 0; e < this.items.length; e++) {
                    var t = this.items[e].getChildByName("item_bg");
                    (t.index = e), t.on(cc.Node.EventType.TOUCH_END, this.itemClick, this);
                }
                this.btnClose.node.on(game.EngineEventType.NodeEvent.click, this.btn_closeView, this),
                    this.btn_receive.node.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_receive, this);
            }),
            (t.prototype.removeEvent = function () {
                for (var e = 0; e < this.items.length; e++)
                    this.items[e].getChildByName("item_bg").off(cc.Node.EventType.TOUCH_END, this.itemClick, this);
                this.btnClose.node.off(game.EngineEventType.NodeEvent.click, this.btn_closeView, this),
                    this.btn_receive.node.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_receive, this);
            }),
            r([_(cc.SpriteFrame)], t.prototype, "item_finish", void 0),
            r([_(cc.SpriteFrame)], t.prototype, "item_bg", void 0),
            r([_(cc.ProgressBar)], t.prototype, "progressTask", void 0),
            r([_([cc.Node])], t.prototype, "items", void 0),
            r([_(cc.Button)], t.prototype, "btnClose", void 0),
            r([_(cc.Button)], t.prototype, "btn_receive", void 0),
            r([f], t)
        );
    })(game.BasePopView);
i.default = y;
